<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('_CU'))
{
	function _CU()
	{
		$host =
			"http://".$_SERVER["SERVER_NAME"].($_SERVER["SERVER_PORT"]==80?"":(":".$_SERVER["SERVER_PORT"])); 
		return $host.$_SERVER['REQUEST_URI'];
	}
}
if ( ! function_exists('_U'))
{
	/***  求URL ******/
	function _U($path,$is_return = false)
	{
		$path = preg_replace('/show\?id=(\d+)/', 'show/\\1.html', $path); 
		// $path = preg_replace('/index\?class-id=(\d+)/', 'index/\\1.html', $path); 
		
		$ci = & get_instance() ; 
		// print_r($_SERVER); 
		if(CONTROL_FOLDER == "front")
		{
			$entry_page = $ci->config->item('entry_page');
			if(empty($entry_page))
			{
				return str_replace("/index.php","" , $_SERVER["SCRIPT_NAME"])."/".$path;
			}
			else
			{
				return str_replace("/index.php","/" . $entry_page , $_SERVER["SCRIPT_NAME"])."/".$path; 
			}
		}
		else
		{
			return  $_SERVER["SCRIPT_NAME"]."/".$path;
		}
	}
}

if ( ! function_exists('_P'))
{
	function _P($path,$with_host = false,$is_return = false)
	{
		$host = 
		"http://".$_SERVER["SERVER_NAME"].($_SERVER["SERVER_PORT"]==80?"":(":".$_SERVER["SERVER_PORT"]));
		$script_name = $_SERVER["SCRIPT_NAME"];
		$base_url = ($with_host?$host:'').trim(dirname($script_name),'\\');
	
		if($is_return)
		{
			return $base_url . "/" . $path ;
		}
		echo  $base_url . "/" . $path;  
	}  
}  

if ( ! function_exists('_V'))
{
	function _V($path,$with_host = false,$is_return = false)
	{
		global $application_folder;
        //  print_r($_SERVER);exit;
		$host = 
		"http://".$_SERVER["SERVER_NAME"].($_SERVER["SERVER_PORT"]==80?"":(":".$_SERVER["SERVER_PORT"]));
		// $url = $_SERVER["SCRIPT_NAME"];
		$script_name = $_SERVER["SCRIPT_NAME"];
		$base_url = ($with_host?$host:'').trim(dirname($script_name),'\\');
        $base_url = trim($base_url,"/");
        $base_url = trim($base_url,"\\");
        (!$with_host && !empty($base_url)) && $base_url = "/".$base_url;
        // $base_url = ".";
        // echo $base_url;exit;
		$view_url = $base_url. "/$application_folder/views/";
		
		if($is_return)
		{
			return $view_url . $path ;
		}
		echo  $view_url . $path; 
	}
}

if ( ! function_exists('_T')) 
{
	function _T($table_name)
	{
		$db_config_path = str_replace('system/',APPPATH,BASEPATH).'config/database'.EXT;
		include(APPPATH.'config/database'.EXT);
		return $db[$active_group]['dbprefix'].$table_name ;   
	}
}

?> 